package javase.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * a,b,c三个方法，里面分别起一个线程，主程序调用getFast()，哪个线程先执行就获取哪个线程的值
 */
public class ArrayBlockingQueueDemo {
    public static ArrayBlockingQueue<Integer> arrayBlockingQueue = new ArrayBlockingQueue(3);

    public static void main(String[] args) {

        getFast();

        //
        try {
            Integer take = arrayBlockingQueue.take();
            System.out.println(take);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static List getFast() {

        List result;
        result = a(arrayBlockingQueue);
        result = b(arrayBlockingQueue);
        result = c(arrayBlockingQueue);

        return result;
    }

    static List a(ArrayBlockingQueue arrayBlockingQueue) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("a开始执行");
                arrayBlockingQueue.add(1);
            }
        }).start();
        return new ArrayList();

    }

    static List b(ArrayBlockingQueue arrayBlockingQueue) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("b开始执行");

                arrayBlockingQueue.add(2);
            }
        }).start();
        return new ArrayList();
    }

    static List c(ArrayBlockingQueue arrayBlockingQueue) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("c开始执行");

                arrayBlockingQueue.add(3);
            }
        }).start();
        return new ArrayList();
    }

}
